package com.soup.lab.basic.initialization;

import java.util.HashMap;
import java.util.Map;

public class Grandfather {

    private static final Map<String, Object> global = createStaticMap("pre-static-block");

    private final Map<String, Object> map = createMap();

    static {
        System.out.println("grandfather static block");
    }

    private static final Map<String, Object> global2 = createStaticMap("after-static-block");

    {
        System.out.println("grandfather pre-constructor block 1");
    }

    public Grandfather() {
        System.out.println("grandfather constructor");
        // 暴露了this, 不提倡
        init();
    }

    {
        System.out.println("grandfather after-constructor block 2");
    }

    protected void init() {
        System.out.println("grandfather init");
    }

    private Map<String, Object> createMap() {
        System.out.println("grandfather init property");
        return new HashMap<>();
    }

    private static Map<String, Object> createStaticMap(String name) {
        System.out.println("grandfather init global property: "+ name);
        return new HashMap<>();
    }

}
